import {
    playMove,
    isWin
} from './game.js'

import showUI from './UI.js'
showUI()
var over = false

window.onkeydown = function (e) {
    if (over) {
        return
    }
    var result = false;
    if (e.key === "ArrowUp") {
        result = playMove("up");
    } else if (e.key === "ArrowDown") {
        result = playMove("down")
    } else if (e.key === "ArrowLeft") {
        result = playMove("left")
    } else if (e.key === "ArrowRight") {
        result = playMove("right")
    }
    if (result) {
        showUI()
        if (isWin()) {
            setTimeout(() => {
                alert('游戏胜利')
                over = true
            }, 100);
        }
    }
}